package com.lottery.ruok.lottrey.adapter.fragmentManager;

import com.lottery.ruok.lottrey.fragment.BaseFragment;
import com.lottery.ruok.lottrey.fragment.DistributionFragment;
import com.lottery.ruok.lottrey.fragment.LongDragonFragment;
import com.lottery.ruok.lottrey.fragment.PrizeNumberFragment;
import com.lottery.ruok.lottrey.fragment.TwoSidedStatisticsFragment;
import com.lottery.ruok.lottrey.retrofitModule.response.LotteryStatOneResponse;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class PrizeListNumgerPageFragmentManager {
    public static final int TYPE_PRIZE_NUMBER = 0;//
    public static final int TYPE_PRIZE_DS = 1;
    public static final int TYPE_PRIZE_LONGDRAGON = 2;
    public static final int TYPE_PRIZE_DISTRIBUT = 3;

    private static HashMap<Integer, BaseFragment> map = new HashMap<>();
    private static LotteryStatOneResponse data;
    private static String[] titles;

    public static BaseFragment getFragment(int key) {
        if (map.containsKey(key)) {
            return map.get(key);
        }
        BaseFragment fragment = null;
        switch (key) {
            case TYPE_PRIZE_NUMBER:
                fragment = new PrizeNumberFragment();
                break;
            case TYPE_PRIZE_DS:
                fragment = new TwoSidedStatisticsFragment();
                break;
            case TYPE_PRIZE_LONGDRAGON:
                fragment = new LongDragonFragment();
                break;
            case TYPE_PRIZE_DISTRIBUT:
                fragment = new DistributionFragment();
                break;
        }
        map.put(key, fragment);
        return fragment;
    }

    public static int getSize() {
        return 0;
    }

    public static String getTitle(int position) {
        if (titles != null && titles.length > 0) {
            return titles[position];
        } else {
            return "";
        }
    }

    public static void setData(LotteryStatOneResponse source) {
        data = source;
        titles = data.getOnetab().split(",");
        setItemData();
    }

    public static void setItemData() {
        Iterator<Map.Entry<Integer, BaseFragment>> entries = map.entrySet().iterator();
        while (entries.hasNext()) {
            Map.Entry<Integer, BaseFragment> entry = entries.next();
            switch (entry.getKey()) {
                case TYPE_PRIZE_NUMBER:
                    PrizeNumberFragment fragment = (PrizeNumberFragment) map.get(entry.getKey());
                    break;
                case TYPE_PRIZE_DS:
                    break;
                case TYPE_PRIZE_LONGDRAGON:
                    break;
                case TYPE_PRIZE_DISTRIBUT:
                    break;
            }
        }
    }


}
